package com.xlh.server.protocol.support.json;

import android.text.Html;

import com.xlh.Utils.FontHandler;
import com.xlh.Utils.GsonManager;
import com.xlh.bean.ProtocolObject.Window;
import com.xlh.interf.IActivity;
import com.xlh.interf.ITakeMessage;

import net.nightwhistler.htmlspanner.HtmlSpanner;

/**
 * Created by mike@Q184377367 on 2018/7/2.
 */

public class RoomTitleServer implements ITakeMessage {

    private IActivity atv;
    private String hasType = "roomTitle";
    private Window protccoObj;
    public RoomTitleServer(IActivity atv){
        this.atv = atv;


    }

    @Override
    public void takeMessage(String t,String s){

        if(!t.equals(this.hasType)) return;

        protccoObj =  GsonManager.gsmgr.jsonToAnyObject(s, Window.class);

        if(protccoObj==null) return;

        final RoomTitleServer me = this;
//收到此命令的时候清空左侧栏和所有出口
        String result = protccoObj.getText();

       // FontHandler fontHandler = new FontHandler(this.atv.getActivity());


        if (me.atv.getActivity().mTitleAdapter != null) {
            me.atv.getActivity().mTitleAdapter.clear();
        }
        me.atv.getActivity().mDirs.clear();
        me.atv.getActivity().mPlaceKey.clear();
        me.atv.getActivity().getOtherExitsViewManager().getDataAdapter().clear();
        me.atv.getActivity().getServerCommHelper().hideAllExits();

      //  me.atv.getActivity().getServerCommHelper().setCurrentExits(Html.fromHtml(result,null,fontHandler));
        me.atv.getActivity().getServerCommHelper().setCurrentExits(this.atv.getActivity().getHtmlSpanner().fromHtml(result));


    }

    @Override
    public boolean takeMessage(String s) {
        return false;
    }

    @Override
    public void init() {

    }

    @Override
    public void atViewLoadAfterInit() {

    }

}
